<?php
require "common.php";
//if ($_POST) {
//    $title = $_POST['title'];
//    $content = $_POST['content'];
//    $category_id = $_POST['category_id'];
//    $time = time();
//    $res = mysql_query("insert into `article` (`title`,`content`,`time`,`category_id`)VALUES ('$title','$content','$time','$category_id')");
//    echo "<script>alert('编辑成功'),location.href=index.php</script>";
//}

//require "templates/add.html";
class AddController extends CommonController{
    function addIndex(){
        if ($_POST){
            $title = $_POST['title'];
            $content = $_POST['content'];
            $category_id = $_POST['category_id'];
            $time = time();
            $res = $this->add("insert into `article` (`title`,`content`,`time`,`category_id`) values ('$title','$content','$time','$category_id')");
            if($res)
                $this->redirect("添加成功",'index.php');
            $this->redirect("添加失败");
        }
        $category = $this->all("select * from category");
        $this->assign("category",$category);
        $this->display("add.html");
    }


}
$add = new AddController();
$add->addIndex();